package com.gin.supermarket_inventory_system.inventory.controller;

import com.gin.security.Constant.Security;
import com.gin.spring.annotation.MyRestController;
import com.gin.spring.vo.response.Res;
import com.gin.supermarket_inventory_system.inventory.docket.InventoryDocket;
import com.gin.supermarket_inventory_system.inventory.dto.form.receipt.ReceiptForm;
import com.gin.supermarket_inventory_system.inventory.dto.form.receipt.ReceiptFormExtra;
import com.gin.supermarket_inventory_system.inventory.enums.InventoryReceiptType;
import com.gin.supermarket_inventory_system.inventory.service.InventoryAmountService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 *
 * @since : 2023/9/26 16:37
 * @author : ginstone
 * @version : v1.0.0
 **/
@Slf4j
@MyRestController(InventoryReceiptPostController.API_PREFIX)
@Tag(name = InventoryReceiptPostController.GROUP_NAME)
@RequiredArgsConstructor
public class InventoryReceiptPostController {
    /**
     *  接口路径前缀
     */
    public static final String API_PREFIX = InventoryDocket.API_PREFIX + "/receipt/post";
    /**
     *  接口文档分组名称
     */
    public static final String GROUP_NAME = "库存单据管理";
    /**
     * 本接口使用的主Service类
     */
    private final InventoryAmountService service;

    @PostMapping("purchase")
    @Operation(summary = "库存进货")
    @PreAuthorize(Security.PRE_AUTHORITY_URI_OR_ADMIN)
    public Res<Void> postPurchase(@RequestBody @Validated ReceiptFormExtra form,
                                  @SuppressWarnings("unused") HttpServletRequest request) {
        service.submit(form, InventoryReceiptType.PURCHASE);
        return Res.success();
    }

    @PostMapping("reject")
    @Operation(summary = "库存退货")
    @PreAuthorize(Security.PRE_AUTHORITY_URI_OR_ADMIN)
    public Res<Void> postReject(@RequestBody @Validated ReceiptFormExtra form,
                                @SuppressWarnings("unused") HttpServletRequest request) {
        service.submit(form, InventoryReceiptType.REJECT);
        return Res.success();
    }

    @PostMapping("cancel")
    @Operation(summary = "销售退货")
    @PreAuthorize(Security.PRE_AUTHORITY_URI_OR_ADMIN)
    public Res<Void> postCancel(@RequestBody @Validated ReceiptForm form,
                                @SuppressWarnings("unused") HttpServletRequest request) {
        service.submit(form, InventoryReceiptType.CANCEL);
        return Res.success();
    }

    @PostMapping("sell")
    @Operation(summary = "销售")
    @PreAuthorize(Security.PRE_AUTHORITY_URI_OR_ADMIN)
    public Res<Void> postSell(@RequestBody @Validated ReceiptForm form,
                              @SuppressWarnings("unused") HttpServletRequest request) {
        service.submit(form, InventoryReceiptType.SELL);
        return Res.success();
    }

    @PostMapping("check")
    @Operation(summary = "盘点")
    @PreAuthorize(Security.PRE_AUTHORITY_URI_OR_ADMIN)
    public Res<Void> postCheck(@RequestBody @Validated ReceiptForm form,
                               @SuppressWarnings("unused") HttpServletRequest request) {
        service.submit(form, InventoryReceiptType.CHECK);
        return Res.success();
    }

    @PostMapping("depletion")
    @Operation(summary = "耗损")
    @PreAuthorize(Security.PRE_AUTHORITY_URI_OR_ADMIN)
    public Res<Void> postDepletion(@RequestBody @Validated ReceiptForm form,
                                   @SuppressWarnings("unused") HttpServletRequest request) {
        service.submit(form, InventoryReceiptType.DEPLETION);
        return Res.success();
    }


}